<?

require_once SITE_ROOT_PATH."/_lib/classes/class.tree.php";

class lurls {


// FUNCTION // get a branch
function get_branch_lurl($tree_id){

	if(isset($tree_id)){
		
		$tree = new tree();
		$params['tree_id'] = $tree_id;
		$branch = $tree->get_branch($params);
		unset($params);
		$branch = $branch[0];

		// Remove 0 / World
		$lineage = substr($branch['lineage'], 2);
		$breadcrumb = explode(',', $lineage);

		foreach($breadcrumb as $crumb_id){
			$params['tree_id'] = $crumb_id;
			$crumb = $tree->get_branch($params);
			$url_string .= make_string_url_friendly($crumb[0]['name'])."/";
		}
		
		switch($branch['type_id']) {
			case 1;
				$full_url_string = MAIN_SITE_ROOT."/destination_guide/".$url_string."destination-".$tree_id.".html";
			break;
			case 2;
				$full_url_string = MAIN_SITE_ROOT."/destination_guide/".$url_string."resort-".$tree_id.".html";
			break;
			case 3;
				$full_url_string = MAIN_SITE_ROOT."/destination_guide/".$url_string."hotel-".$tree_id.".html";
			break;
		}

		return $full_url_string;
	
	}

}





// FUNCTION // get holiday lurl
function get_holiday_lurl($params){

/*if(!empty($params['tree_id'])){

	$hotels = new hotels();
	$tree = new tree();
	$destinations = new destinations();
	
	$branch = $tree->get_branch($params['tree_id']);
	$lineage = substr($branch[0]['lineage'], 2);
	
	$breadcrumb = explode(',', $lineage);
	
	foreach($breadcrumb as $crumb_id){
	
		$branch = $tree->get_branch($crumb_id);
		
		if(($branch['type_id'] == '1') OR ($branch['type_id'] == '2')){
		
			$params['tree_id'] = $crumb_id;
			$crumb_destination = $destinations->get_destination($params);
			$url_string .= make_string_url_friendly($crumb_destination['name'])."/";
		
		}
		
		if($branch['type_id'] == '3'){
		
			$params['tree_id'] = $crumb_id;
			$crumb_destination = $hotels->get_hotel($params);
			$url_string .= make_string_url_friendly($crumb_destination['name'])."/";
		
		}

	}

}*/


if(!empty($params['reference_id'])){

	$full_url_string = MAIN_SITE_ROOT."/holidays/".$url_string."holiday-".$params['reference_id'].".html";
	
	return $full_url_string;
}

}
// END FUNCTION


// FUNCTION // get hotel from search result lurl
function get_hotel_result_lurl($params){

if(!empty($params['tree_id'])){

	$hotels = new hotels();
	$tree = new tree();
	$destinations = new destinations();
	
	$lineage = $tree->get_lineage($params['tree_id']);
	$lineage = substr($lineage, 2);
	
	$breadcrumb = explode(',', $lineage);
	
	foreach($breadcrumb as $crumb_id){
	
		$branch = $tree->get_branch($crumb_id);
		
		if(($branch['type_id'] == '1') OR ($branch['type_id'] == '2')){
		
			$params['tree_id'] = $crumb_id;
			$crumb_destination = $destinations->get_destination($params);
			$url_string .= make_string_url_friendly($crumb_destination['name'])."/";
		
		}
		
		if($branch['type_id'] == '3'){
		
			$params['tree_id'] = $crumb_id;
			$crumb_destination = $hotels->get_hotel($params);
			$url_string .= make_string_url_friendly($crumb_destination['name'])."/";
		
		}


	}

	$full_url_string = MAIN_SITE_ROOT."/hotels/".$url_string."hotel-".$params['tree_id'].".html";
	
	return $full_url_string;

}

}
// END FUNCTION




function holiday_list_lurl($params){

	if(empty($params['pax_adult'])) $params['pax_adult'] = 2;
	if(empty($params['pax_child'])) $params['pax_child'] = 0;

	$url_string = "/holidays/results-".$params['departure_airport']."-".$params['destination_airport']."-".$params['departure_date']."-".$params['nights']."-".$params['pax_adult']."-".$params['pax_child'].".html";
	
	return $url_string;
	
}



// FUNCTION // get hotel review_lurl
function get_hotel_review_lurl($tree_id){

	
	if(isset($tree_id)){
		
		$tree = new tree();
		$params['tree_id'] = $tree_id;
		$branch = $tree->get_branch($params);
		unset($params);
		$branch = $branch[0];

		// Remove 0 / World
		$lineage = substr($branch['lineage'], 2);
		$breadcrumb = explode(',', $lineage);

		foreach($breadcrumb as $crumb_id){
			$params['tree_id'] = $crumb_id;
			$crumb = $tree->get_branch($params);
			$url_string .= make_string_url_friendly($crumb[0]['name'])."/";
		}
		
		$full_url_string = MAIN_SITE_ROOT."/reviews/".$url_string."reviews-".$tree_id.".html";

		
		return $full_url_string;
	
	}


}
// END FUNCTION


function get_hotel_review_add_lurl($tree_id){

	$url_string = MAIN_SITE_ROOT."/reviews/add.html?tree_id=".$tree_id;
	
	return $url_string;
	
}

}
?>